<template>
  <div class="addEditDialog ">
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="35%">
      
     
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('ruleFormref')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { mapState } from 'vuex';
export default {
  name: 'news',
  data () {
    return {
      dialogVisible: false,
      title:'',
      url:'',
      roleName:'',
      roleStatus:'',
      treeList:[],
      defaultTreeCheck:[] ,
      param:{
        menuIdList:[],
        roleId:null
      },
     
      checkStrictly:true,               
    }
  },
  // props: {
  //     id:{
  //         type: String,
  //         required: true
  //     }      
  // },
  methods: { 
    //获取  树数据
    getTree(roleId){        
      this.$axios({
          method: "get",
          url: '/system/menu/other/checked/list',
          params:{
            roleId:roleId
          },
          headers: {
              "Content-Type": "application/json;charset=UTF-8"
          }
      }).then(res => {                        
          if (res.data.code == 0) { 
            this.treeList=res.data.data.checkMenuInfoTreeCheckDTO;
            this.defaultTreeCheck=res.data.data.checkedMenuIdList;                                           
          }else {                                  
             this.$message({
                message: res.msg,
                type: 'warning'
              }); 
          }            

      }).catch(error=>{
          this.$message({
            message: error.msg,
            type: 'error'
          }); 
      }); 
       
    },

        //添加&编辑弹窗的tree  选中获取
    handleCheckChange () {
      var res = this.$refs.tree.getCheckedNodes()
      var arr = []
      res.forEach((item) => {
        arr.push(item.id)
      });
      this.param.menuIdList=arr;
      this.addOrderform.menuIdList=this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys()) 
    },

   
    //弹窗加载  数据渲染
    loadDialogData(title){
      this.dialogVisible=true;
      this.title=title;      
      // this.$store.dispatch('getlist',{param:'',url:this.url});  

    },
    submitForm(formName) {                                                                         
      this.$store.dispatch('postform',{param:this.param,url:this.url}).then(() => {
        if(this.addEdit.code==0){
          this.$message({
            message: this.addEdit.msg,
            type: 'success'
          });               
          this.dialogVisible=false;  
          this.$emit('fatherMethod'); 
        }else{
           this.$message({
            message: this.addEdit.msg,
            type: 'warning'
          }); 
        }              
      }).catch(() => {
           this.$message({
            message: this.addEdit.msg,
            type: 'error'
          });           
      })       
     
    },
  
  },
  computed:{
    
    ...mapState(['list','addEdit'])
  },
  mounted(){         
        
  },
  created() {     
      
  },
}
</script>

<style scoped>


</style>
<style>

</style>
